package com.pansoft.openplanet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.chat.utils.LXGlideImageLoader;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.PointCardBean;
import com.pansoft.openplanet.cardstack.CardStackView;
import com.pansoft.openplanet.cardstack.StackAdapter;


public class CardStackAdapter extends StackAdapter<PointCardBean> {
    private ClickListener mClickListener;
    private Context mContext;
    public CardStackAdapter(Context context, ClickListener clickListener) {
        super(context);
        this.mContext = context;
        mClickListener = clickListener;

    }

    @Override
    public void bindView(PointCardBean data, int position, CardStackView.ViewHolder holder) {
            ColorItemViewHolder h = (ColorItemViewHolder) holder;
            h.onBind(data, position);
    }

    @Override
    protected CardStackView.ViewHolder onCreateView(ViewGroup parent, int viewType) {
        View view;
        view = getLayoutInflater().inflate(R.layout.item_list_card, parent, false);
        return new ColorItemViewHolder(view);

    }

    @Override
    public int getItemViewType(int position) {
            return R.layout.item_list_card;
    }

     class ColorItemViewHolder extends CardStackView.ViewHolder {
        View mLayout;
        TextView mTextTitle;
        TextView tvNum;
        TextView tvBalance;
        Button btnGoRecharge;
        ImageView ivBackground;
        ImageView ivIconLeft;

        View flGoRecharge;

        public ColorItemViewHolder(View view) {
            super(view);
            mLayout = view.findViewById(R.id.frame_list_card_item);
            btnGoRecharge = view.findViewById(R.id.btn_go_recharge);
            flGoRecharge = view.findViewById(R.id.fl_go_recharge);
            ivBackground = view.findViewById(R.id.iv_background);
            mTextTitle = view.findViewById(R.id.tv_name);
            tvNum = view.findViewById(R.id.tv_num);
            tvBalance = view.findViewById(R.id.tv_balance);
            ivIconLeft = view.findViewById(R.id.iv_icon_left);
        }

        @Override
        public void onItemExpand(boolean b) {
            flGoRecharge.setVisibility(b ? View.VISIBLE : View.GONE);
        }

        public void onBind(PointCardBean data, final int position) {
            mTextTitle.setText(data.getName());
            tvNum.setText(data.getNum());
            tvBalance.setText(mContext.getString(R.string.open_planet_point_card_balance, data.getBalance()));
            if(data.getBackGround() != 0){
                LXGlideImageLoader.getInstance().displayRoundCornerImage(mContext,ivBackground,data.getBackGround(),0,0,10);
            }else {
                LXGlideImageLoader.getInstance().displayRoundCornerImage(mContext,ivBackground,data.getCardBg(),0,0,10);
            }

            if(data.getIconLeft()!=0){
                LXGlideImageLoader.getInstance().displayImage(mContext,ivIconLeft,data.getIconLeft());
            }else {
                LXGlideImageLoader.getInstance().displayImage(mContext,ivIconLeft,data.getCardImg());
            }

            btnGoRecharge.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mClickListener.onClick(view,position);
                }
            });
        }

    }
    public interface ClickListener {
       public void onClick(View view,int position);
    }

}
